package tech.aistar.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalTime;
import java.util.Date;
import java.util.function.Supplier;

/**
 * 本类用来演示: 实现自动填充处理器
 *
 * @author: success
 * @date: 2021/6/3 9:59 上午
 */
@Component //需要注册到Spring容器中
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
//        this.strictFillStrategy(metaObject, "createTime", new Supplier<Object>() {
//            @Override
//            public Object get() {
//                return new Date();
//            }
//        });
        this.strictFillStrategy(metaObject, "createTime",Date::new);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictFillStrategy(metaObject,"updateTime",Date::new);
    }
}
